<?php

/**
 * User: Administrator
 * Date: 2017/10/20
 * Time: 11:26
 */

namespace Kinfy;

class Config
{
    private static $_configs = [];

    //public static $theme;


    public static function get($key)
    {
        //如果存在.号，而且不是第一个（位置是0）
        if (strpos($key, '.') > 0) {
            //把它分解，并返回给数组，假设$key=view.theme
            $keyarr = explode('.', $key, 2);

            //如果没有一维数组，$_configs['view']
            if (!isset(self::$_configs[$keyarr[0]])) {
                //indclude
                self::$_configs[$keyarr[0]] = include __DIR__ . '/../../config/' . $keyarr[0] . '.php';
            }
            return self::$_configs[$keyarr[0]][$keyarr[1]];
        } else {
            return self::$_configs[$key];
        }

    }

    public static function set($key, $value)
    {
        if (strpos($key, '.') > 0) {
            $keyarr = explode('.', $key, 2);
            self::$_configs[$keyarr[0]][$keyarr[1]] = $value;
        } else {
            self::$_configs[$key] = $value;
        }
    }

    public static function getAll($pre = null)
    {
        if ($pre) {
            return self::$_configs[$pre];
        } else {
            return self::$_configs;
        }
    }

}

